<template>
	<view>
		<uni-list>
			<uni-list-item v-for="item,index in newsData" :key="index+''" 
			:title="item.title" :clickable="true" :rightText="item.date"
			@click="toNewsDetail(item.id)"
			></uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newsData: [{
					"id": 4,
					"title": "时事新闻2",
					"content": "时事新闻2内瓤",
					"type": "时事",
					"date": "2024-03-01"
				}]
			}
		},
		methods: {
			toNewsDetail(id){
				uni.navigateTo({
					url:'/pages/news/newsDetail?id='+id
				})
			}
		},
		onLoad() {
			uni.request({
				url: 'http://localhost:8090/foodapp/news/list',
				method: 'POST',
				data: {},
				success: res => {
					// 如果正确返回，则将data赋值给newsData
					if (res.data.success) {
						this.newsData = res.data.data
					} else{
						this.newsData=[]
					}
				},
				fail: () => {
					uni.showToast({
						title: '网络失败',
						icon: 'none'
					});
				},
				complete: () => {}
			});
		}
	}
</script>

<style>
.container{
	padding: 20px;
	font-size: 14px;
	line-height: 24px;
}
</style>
